package cn.pzhu.edu.dao;

import java.util.ArrayList;

import java.sql.*;
import cn.pzhu.edu.entity.User;
import cn.pzhu.edu.util.JdbcUtil;

public class UserDao {
	 public  static ArrayList<User> getAllUser()
	 {
		 Connection connection=null;
		 Statement sta=null;
		 ResultSet res=null;
		 try{
			    ArrayList<User> list = new ArrayList<>();
				 connection = JdbcUtil.getConnection();
				String sql = "select * from user";
				 sta = connection.createStatement();
				 res = sta.executeQuery(sql);
				 
				while(res.next()){
					User user = new User(res.getString(1),res.getString(2));
					list.add(user);
				}
				return list;
			}
		 
			catch(Exception e){
				e.printStackTrace();
			}finally{
				JdbcUtil.close(connection, sta, res);
			}
		return null;
	 }
}
